<extend name="Public:base" />
<block name="header_js">
<script type="text/javascript">
	$(function(){

		$("#form_do").submit(function(){
			var name = $("input[name='name']");
			if($.trim(name.val())==''){
				layer.tips('名称不能为空', "input[name='name']", {
				  tips: [3, '#78BA32']
				});
				return false;			
			}else {
			}

		});


		$("input[name='type']").click(function(){    
            
            var checked = $(this).prop('checked'); 
            var nextEname = $(this).parents('.form-group').next();//ename; 

            if(checked) {
                nextEname.find('label').html('链接地址：');
                nextEname.find('span').hide();
            }else {
            	nextEname.find('label').html('别名(拼音)：');
            	nextEname.find('span').show();
            }
            
        });
        
        autoHide();
        function autoHide(){
        	var inputs = $("input[name='type']")
        	var nextEname = inputs.parents('.form-group').next();//ename;
            
            if(inputs.prop('checked')) {
                nextEname.find('label').html('链接地址：');
                nextEname.find('span').hide(); 
            }

        }



        $("select[name='modelid']").change(function(){
        	var styleId = $(this).val();
			setStyleSelect(styleId);
		});
		
		function setStyleSelect(id){
			var template_list = $("select[name='template_list']");
        	var template_show = $("select[name='template_show']");        	
			switch (id){
				<foreach name='mlist' key='key' item='v'>				
				case '{$v.id}':
					//template_list.val("{$v.template_list}");
					template_list.find("option[value='{$v.template_list}']").prop("selected","selected");
					template_show.find("option[value='{$v.template_show}']").prop("selected","selected");
				 	break;				 	
				</foreach>
			}

		}

    });
</script>

<script type="text/javascript">
$(function () {
	//缩略图上传
	var litpic_tip = $(".litpic_tip");
	var btn = $(".up-picture-btn span");
	$("#fileupload").wrap("<form id='myupload' action='{:U('Public/upload',array('img_flag' => 1))}' method='post' enctype='multipart/form-data'></form>");
    $("#fileupload").change(function(){
    	if($("#fileupload").val() == "") return;
		$("#myupload").ajaxSubmit({
			dataType:  'json',
			beforeSend: function() {
        		$('#litpic_show').empty();
				btn.html("上传中...");
    		},
			success: function(data) {
				if(data.state == 'SUCCESS'){
					var fileSize = parseFloat(data.info[0].size/1024).toFixed(2);
					litpic_tip.html(""+ data.info[0].name +" 上传成功("+ fileSize +"k)");
					var img = data.info[0].url;//原图
					var timg = data.info[0].turl;//缩略图
					$('#litpic_show').html("<img src='"+timg+"' width='120'>");
					$("#litpic").val(timg);
				}else {
					litpic_tip.html(data.state);		
				}			
					btn.html("添加图片");

			},
			error:function(xhr){
				btn.html("上传失败");
				litpic_tip.html(xhr);
			}
		});
	});


	
});




$(function () {

	$('#BrowerPicture').click(function(){
		layer.open({
			type: 2,
			title: 'XYHCMS',
			shadeClose: true,
			shade: 0.5,
			area: ['670px', '350px'],
			content: "{:U('Public/browseFile', array('stype' => 'picture'))}"
		});
	});	

});


function selectPicture(sfile) {
	layer.msg('选择文件成功')
	$("#litpic").val(sfile);
	$('#litpic_show').html("<img src='"+sfile+"' width='120'>");
}



</script>
	
</block>

<block name="content">
	<div class="row">
		<div class="col-lg-12">
			<h3 class="page-header"><em class="glyphicon glyphicon-cloud-upload"></em> 
			{$type}    
		    </h3>
		</div>
		
	</div>


	<div class="row">
		<div class="col-lg-12">
			<div>
			
				<!-- Nav tabs -->			
				<ul class="nav nav-tabs" role="tablist">
					<li role="presentation" class="active">
						<a href="#home" aria-controls="home" role="tab" data-toggle="tab">基本选项</a>
					</li>
					<li role="presentation">
						<a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">高级设置</a>
					</li>
					<li role="presentation">
						<a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">权限设置</a>
					</li>
				</ul>

				<form method='post' class="form-horizontal" id="form_do" name="form_do" action="{:U('edit')}">
					<!-- Tab panes -->			
					<div class="tab-content" style="margin-top:20px;">
						<div role="tabpanel" class="tab-pane active" id="home">
							<div class="form-group">
								<label for="inputProName" class="col-sm-2 control-label">所属栏目</label>
								<div class="col-sm-9">
									<select name="pid" class="form-control">
										<option value="0">顶级栏目</option>
										<foreach name='cate' item='v'>
										<option value="{$v.id}" <if condition="$data['pid'] eq $v['id']">selected="selected"</if>>{$v.delimiter}{$v.name}</option>
										</foreach>
									</select>									
								</div>
							</div>

							<div class="form-group">
								<label for="inputModelId" class="col-sm-2 control-label">内容模型</label>
								<div class="col-sm-9">
									<select name="modelid" class="form-control">
										<foreach name='mlist' item='v'>
										<option value="{$v.id}" <if condition="$data['modelid'] eq $v['id']">selected="selected"</if>>{$v.name}</option>
										</foreach>
									</select>									
								</div>
							</div>							

							<div class="form-group">
								<label for="inputName" class="col-sm-2 control-label">栏目名称</label>
								<div class="col-sm-9">
									<input type="text" name="name" id="inputName" value="{$data.name}" class="form-control" placeholder="栏目名称" />									
								</div>
							</div>
							<div class="form-group">
								<label for="inputType" class="col-sm-2 control-label">外部链接</label>
								<div class="col-sm-9">
									<label class="checkbox-inline">
										<input type="checkbox" name="type" id="inputType" value="1"  <if condition="$data['type'] eq 1">checked="checked"</if> />外部链接				
									 </label>
								</div>
							</div>
							<div class="form-group">
								<label for="inputEname" class="col-sm-2 control-label">别名(拼音)</label>
								<div class="col-sm-9">
									<input type="text" name="ename" id="inputEname" value="{$data.ename}" class="form-control" />	
									<span>只能包含字母，数字</span>								
								</div>
							</div>
							<div class="form-group">
								<label for="inputEname" class="col-sm-2 control-label">栏目图片</label>
								<div class="col-sm-5">
									    <input type="text" class="form-control" name="catpic" id="litpic" value="{$data.catpic}" placeholder="栏目图片地址" />	
								</div>
								<div class="col-sm-5">
									<button class="btn btn-primary" type="button" id="BrowerPicture"><em class="glyphicon glyphicon-plus-sign"></em> 选择站内图片</button>
										<div class="btn btn-success up-picture-btn">
									        <span><em class="glyphicon glyphicon-plus-sign"></em>添加图片</span>										        
									        <input id="fileupload" type="file" name="mypic">
									    </div>							
								</div>
							</div>


							<div class="form-group">
								<label for="" class="col-sm-2 control-label"></label>
								<div class="col-sm-9">
									<div class="litpic_tip"></div>
									<div id="litpic_show">
										<notempty name="data['catpic']"><img src="{$data.catpic}" width='120' /></notempty>
									</div>							
								</div>
							</div>

							<div class="form-group">
								<label for="inputName" class="col-sm-2 control-label">排序</label>
								<div class="col-sm-9">
									<input type="text" name="sort" id="inputSort" class="form-control" value="{$data.sort}" />									
								</div>
							</div>

							<div class="form-group">
								<label for="inputName" class="col-sm-2 control-label">显示</label>
								<div class="col-sm-9">
									<label class="radio-inline">
									 	<input type="radio" name="status" value="1" <if condition="$data['status'] eq 1">checked="checked"</if>/>显示				
									 </label>
									<label class="radio-inline">
									 	<input type="radio" name="status" value="0" <if condition="$data['status'] eq 0">checked="checked"</if> />隐藏		
									 </label>	
								</div>
							</div>

						</div>
						<div role="tabpanel" class="tab-pane" id="profile">
							<div class="form-group">
								<label for="inputProName" class="col-sm-2 control-label">栏目模板</label>
								<div class="col-sm-9">
									<select name="template_list" class="form-control">
										<foreach name='styleListList' item='v'>
											<option value="{$v}" <if condition="$data['template_list'] eq $v">selected="selected"</if>>{$v}</option>
										</foreach>
									</select>									
								</div>
							</div>

							<div class="form-group">
								<label for="inputTemplateShow" class="col-sm-2 control-label">内容页模板</label>
								<div class="col-sm-9">
									<select name="template_show" id="inputTemplateShow" class="form-control">
										<foreach name='styleShowList' item='v'>
										<option value="{$v}" <if condition="$data['template_show'] eq $v">selected="selected"</if>>{$v}</option>
										</foreach>
									</select>									
								</div>
							</div>							

							<div class="form-group">
								<label for="inputSeotitle" class="col-sm-2 control-label">Seo标题</label>
								<div class="col-sm-9">
									<input type="text" name="seotitle" id="inputSeotitle" value="{$data.seotitle}" class="form-control" placeholder="Seo标题" />
								</div>
							</div>
							<div class="form-group">
								<label for="inputKeywords" class="col-sm-2 control-label">关键词</label>
								<div class="col-sm-9">
									<input type="text" name="keywords" id="inputKeywords" value="{$data.keywords}" class="form-control" placeholder="关键词" />						
								</div>
							</div>
							<div class="form-group">
								<label for="inputDescription" class="col-sm-2 control-label">栏目描述</label>
								<div class="col-sm-9">
									<textarea name="description" id="inputDescription" class="form-control" placeholder="栏目描述">{$data.description}</textarea>							
								</div>
							</div>	

						</div>
						<div role="tabpanel" class="tab-pane" id="messages">
							<div class="form-group">
								<label for="inputProName" class="col-sm-2 control-label">管理员组权限</label>
								<div class="col-sm-9">
									<table class="table table-hover xyh-table-bordered-out-small">
										<thead>
											  <tr class="active">
											    <th>管理员组名称</th>
											    <th>查看</th>				    
											    <th>添加</th>				    
											    <th>修改</th>				    
											    <th>删除</th>
											    <th>移动</th>		    
											    <th>回收站</th>	    
											    <th>还原</th>	    
											    <th>清除</th>
											  </tr>
										  </thead>
										  <tbody>
										  <foreach name='roleList' item='v'>	
										  <tr>
										    <td>{$v.name}</td>
										    <td align="center"><input type="checkbox" name="acc_roleid[]" value="index,{$v.id}" <if condition="check_category_access($data['id'],'index',$v['id']) eq 1">checked="checked"</if> /></td>
										    <td align="center"><input type="checkbox" name="acc_roleid[]" value="add,{$v.id}" <if condition="check_category_access($data['id'],'add',$v['id']) eq 1">checked="checked"</if> /></td>
										    <td align="center"><input type="checkbox" name="acc_roleid[]" value="edit,{$v.id}" <if condition="check_category_access($data['id'],'edit',$v['id']) eq 1">checked="checked"</if> /></td>
										    <td align="center"><input type="checkbox" name="acc_roleid[]" value="del,{$v.id}" <if condition="check_category_access($data['id'],'del',$v['id']) eq 1">checked="checked"</if> /></td>
										    <td align="center"><input type="checkbox" name="acc_roleid[]" value="move,{$v.id}" <if condition="check_category_access($data['id'],'move',$v['id']) eq 1">checked="checked"</if> /></td>
										    <td align="center"><input type="checkbox" name="acc_roleid[]" value="trach,{$v.id}" <if condition="check_category_access($data['id'],'trach',$v['id']) eq 1">checked="checked"</if> /></td>
										    <td align="center"><input type="checkbox" name="acc_roleid[]" value="restore,{$v.id}" <if condition="check_category_access($data['id'],'restore',$v['id']) eq 1">checked="checked"</if> /></td>
										    <td align="center"><input type="checkbox" name="acc_roleid[]" value="clear,{$v.id}" <if condition="check_category_access($data['id'],'clear',$v['id']) eq 1">checked="checked"</if> /></td>
										  </tr>
										  </foreach>
										  </tbody>
									</table>							
								</div>
							</div>

							<div class="form-group">
								<label for="inputTemplateShow" class="col-sm-2 control-label">会员组权限</label>
								<div class="col-sm-9">
									<table class="table table-hover xyh-table-bordered-out-small">
									  <thead>
										  <tr class="active">
										    <th>会员组名称</th>
										    <th>允许访问</th>
										  </tr>
									  </thead>
									  <tbody>
										  <foreach name='groupList' item='v'>	
										  <tr>
										    <td>{$v.name}</td>
										    <td align="center"><input type="checkbox" name="acc_groupid[]" value="visit,{$v.id}" <if condition="check_category_access($data['id'], 'visit', $v['id'], 0) eq 1">checked="checked"</if> /></td>
										  </tr>
										  </foreach>
									  </tbody>
									</table>								
								</div>
							</div>

						</div>
					</div>
					<div class="row">
						<div class="col-sm-offset-2 col-sm-9">
							<input type="hidden" name="id" value="{$data.id}"/>			
							<input type="hidden" name="oldmodelid" value="{$data.modelid}"/>
							<div class="btn-group">
								<button type="submit" class="btn btn-primary"> <i class="glyphicon glyphicon-saved"></i>
									保存
								</button>
								<button type="button" onclick="goUrl('{:U('index')}')" class="btn btn-default"> <i class="glyphicon glyphicon-chevron-left"></i>
									返回
								</button>
							</div>
						</div>
					</div>
				</form>

			</div>
	
		</div>
	</div>

		


</block>